package com.tanhua.server.controller;

import com.tanhua.domain.db.PageResult;
import com.tanhua.domain.vo.MoreDataVo;
import com.tanhua.domain.vo.VideoVo;
import com.tanhua.server.service.CommentService;
import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/smallVideos")
public class VideoController {

    //注入VideoService对象
    @Autowired
    private VideoService videoService;
    //注入CommentService对象
    @Autowired
    private CommentService commentService;

    /**
     * 发布小视频
     */
    @PostMapping
    public ResponseEntity uploadVideo(MultipartFile videoThumbnail,MultipartFile videoFile) {
        //调用service层
        videoService.uploadVideo(videoThumbnail,videoFile);
        //返回状态信息
       return ResponseEntity.ok(null);
    }

    /**
     * 小视频列表
     */
    @GetMapping
    public ResponseEntity findVideo(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10")Integer pagesize) {

        //这个地方接受的参数有点问题 需要处理
        page=page>0?page:1;
        //调用publishService
        PageResult<VideoVo> videoVoPageResult = videoService.findVideo(page,pagesize);
        //返回状态码
        return ResponseEntity.ok(videoVoPageResult);
    }

    /**
     * 关注作者
     */
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity addFollowUserAndFriend(@PathVariable("uid") Long uid) {
        //a.接受作者用户id 调用service层 传入作者用户id
        videoService.addFollowUserAndFriend(uid);
        //b.返回状态信息
        return ResponseEntity.ok(null);
    }

    /**
     * 取消关注
     */
    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity unFollowUserAndFriend(@PathVariable("uid") Long uid) {
        //a.接受作者用户id 调用service层 传入作者用户id
        videoService.unFollowUserAndFriend(uid);
        //b.返回状态信息
        return ResponseEntity.ok(null);
    }

    /**
     * 视频-点赞
     */
    @PostMapping("/{id}/like")
    public ResponseEntity videoLive(@PathVariable("id")String id) {
        //调用CommentService方法 返回视频点赞数量
        commentService.videoLikeCount(id);
        //返回状态信息
        return  ResponseEntity.ok(null);
    }


    /**
     * 视频-取消点赞
     */
    @PostMapping("/{id}/dislike")
    public ResponseEntity videoDisLive(@PathVariable("id")String id) {
        //调用CommentService方法 返回视频点赞数量
        commentService.videoDisLive(id);
        //返回状态信息
        return  ResponseEntity.ok(null);
    }









}
